<template>
	<view class="container">
		<testcom :diyItems="diyItems"></testcom>
	</view>
</template>
<script>
	import testcom from '../../components/div/index.vue'
	export default {
		components: {testcom},
		data() {
			return {
				// 页面参数
				options: [],
				// 页面元素
				diyItems: [],
				show: false,
				
			}
		},
		/**
		 * 生命周期函数--监听页面加载
		 */
		onLoad: function(options) {
			let _this = this;
			// 页面id
			_this.page_id = options.page_id;

			uni.setStorageSync('page_id', options.page_id);
			// 加载页面数据
			_this.getPageData();

		},
		/**
		 * 下拉刷新
		 */
		onPullDownRefresh: function() {
			// 获取首页数据
			this.getPageData(function() {
				uni.stopPullDownRefresh();
			});
		},
		methods: {
			/*2.用正则表达式实现html解码*/
			htmlDecodeByRegExp: function(str) {
				var s = "";
				if (str.length == 0) return "";
				s = str.replace(/&amp;/g, "&");
				s = s.replace(/&lt;/g, "<");
				s = s.replace(/&gt;/g, ">");
				s = s.replace(/&nbsp;/g, " ");
				s = s.replace(/&#39;/g, "\'");
				s = s.replace(/&quot;/g, "\"");
				return s;
			},
			/**
			 * 加载页面数据
			 */
			getPageData: function(callback) {
				let _this = this;
				this._get('api/mobilediy.index/getPageInfo', {
					page_id: _this.page_id
				}, function(result) {
					// 设置顶部导航栏栏
					_this.setPageBar(result.data.page);
					_this.setData({
						diyItems: result.data.items,
					});
					// 回调函数
					typeof callback === 'function' && callback();
				});
				
			},

			/**
			 * 设置顶部导航栏
			 */
			setPageBar: function(page) {
				// 设置页面标题
				uni.setNavigationBarTitle({
					title: page.params.title
				});
				// 设置navbar标题、颜色
				uni.setNavigationBarColor({
					frontColor: page.style.titleTextColor === 'white' ? '#ffffff' : '#000000',
					backgroundColor: page.style.titleBackgroundColor
				})
			},

		}
	}
</script>
<style lang="scss">
	page {
		background: #fff !important;
	}

</style>
